﻿using System;
using System.Globalization;
using System.Runtime.Serialization;
using Istace.Framework.Mapping.Core.Interfaces;

namespace Istace.Framework.Mapping.Core.Exceptions
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [Serializable]
    public class BadTypeRepositoryIndexingException<T> : RepositoryBaseException<T>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="BadTypeRepositoryIndexingException{T}"/> class.
        /// </summary>
        public BadTypeRepositoryIndexingException() : base(String.Empty, null, String.Empty, null)
        {
            
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BadTypeRepositoryIndexingException{T}" /> class.
        /// </summary>
        /// <param name="message">The message that describes the error.</param>
        public BadTypeRepositoryIndexingException(string message)
            : base(message, null, String.Empty, null)
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BadTypeRepositoryIndexingException{T}" /> class.
        /// </summary>
        /// <param name="message">The message that describes the error.</param>
        /// <param name="exception">The exception.</param>
        public BadTypeRepositoryIndexingException(string message, Exception exception)
            : base(message, exception)
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BadTypeRepositoryIndexingException{T}"/> class.
        /// </summary>
        /// <param name="info">The serializationinfo.</param>
        /// <param name="context">The streaming context.</param>
        protected BadTypeRepositoryIndexingException(SerializationInfo info, StreamingContext context) : base(info, context)
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BadTypeRepositoryIndexingException{T}"/> class.
        /// </summary>
        /// <param name="instanceToIndex">Instance of the object to index.</param>
        /// <param name="key">The key.</param>
        /// <param name="targetRepository">The target repository.</param>
        public BadTypeRepositoryIndexingException(T instanceToIndex, string key, IIndexedRepository<T> targetRepository)
            : base(String.Format(CultureInfo.InvariantCulture, "The object of type {0} don't match the repository type {1}.", instanceToIndex.GetType().FullName, typeof(T).FullName), 
                    instanceToIndex, 
                    key, 
                    targetRepository)
        {
        }
    }
}
